package com.flowerstore.controller;

import com.flowerstore.entity.Flower;
import com.flowerstore.service.FlowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class FlowerController {
    
    @Autowired
    private FlowerService flowerService;
    
    @GetMapping("/flowers")
    public ResponseEntity<List<Flower>> getAllFlowers() {
        return ResponseEntity.ok(flowerService.getAllFlowers());
    }
    
    @PostMapping("/add-flower")
    public ResponseEntity<Flower> addFlower(@RequestBody Flower flower) {
        return ResponseEntity.ok(flowerService.addFlower(flower));
    }
    
    @PostMapping("/update-flower/{id}")
    public ResponseEntity<Flower> updateFlower(@PathVariable Long id, @RequestBody Flower flower) {
        return ResponseEntity.ok(flowerService.updateFlower(id, flower));
    }
    
    @PostMapping("/del-flower/{id}")
    public ResponseEntity<Void> deleteFlower(@PathVariable Long id) {
        flowerService.deleteFlower(id);
        return ResponseEntity.ok().build();
    }
} 